package com.fanbai.score.business.activity;

import android.graphics.Bitmap;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.fanbai.score.R;
import com.fanbai.score.business.beans.OrderInfo_Bean;
import com.fanbai.score.business.http.Busin_Order_RequestNet;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ImageUtils;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.common.zxing.encoding.EncodingUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by acer on 2017/5/13.
 * 购物详情
 */

public class OrderDetails_Activity extends BaseActivity{

    @BindView(R.id.businessActivityOrderInfo_jifen)
    TextView jifenText;
    @BindView(R.id.businessActivityOrderInfo_zongjia)
    TextView zongjiaText;
    @BindView(R.id.businessActivityOrderInfo_dec)
    TextView decText;
    @BindView(R.id.businessActivityOrderInfo_decEditBut)
    TextView decEditText;
    @BindView(R.id.businessActivityOrderDetails_decEdit)
    EditText decEdit;
    @BindView(R.id.businessActivityOrderDetails_imgErWeiMa)
    ImageView erWeiMaImg;

    @OnClick(R.id.businessActivityOrderInfo_decEditBut)
    public void onClick(){
        if(decEdit.isEnabled()){
            decEdit.setEnabled(false);
            decEditText.setText("编辑");
        }else{
            decEdit.setEnabled(true);
            decEditText.setText("保存");
        }
    }

    @Override
    protected int getLayoutID() {
        return R.layout.business_activity_orderdetails;
    }

    @Override
    public String getTitleName() {
        return "积分详情";
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        String oid = getIntent().getExtras().getString("oid");
        getorderinfobyoid(oid);
    }

    private void setViewData(OrderInfo_Bean bean){

        jifenText.setText("积分："+bean.getOscore());
        zongjiaText.setText("总价："+bean.getOtotalprice());
        decText.setText("商品描述\n  "+bean.getOproductdesc());

            //生成二维码图片，第一个参数是二维码的内容，第二个参数是正方形图片的边长，单位是像素  
        Bitmap qrcodeBitmap = EncodingUtils.createQRCode("{\"type\":\"order\",\"oid\":\""+bean.getOid()+"\"}"
                , 500, 500, null);
        erWeiMaImg.setImageBitmap(qrcodeBitmap);
    }

    @Override
    protected void initListener() {

    }
    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }

    private void getorderinfobyoid(String oid){
        showDialog();
        Busin_Order_RequestNet.getorderinfobyoid(ctx, oid, new CallBack<OrderInfo_Bean>() {
            @Override
            public void onSuccess(String code, String msg, OrderInfo_Bean s) {
                hideDialog();
                setViewData(s);
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }

}
